/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package stm_database;

import java.util.ArrayList;
import java.util.Arrays;
/**
 *
 * @author stepj5am
 */
public class DatabaseItem {
    /**
     * atributy polozky
     */
    protected ArrayList<String> items;
    /**
     * oddelovac atributu ve stringu
     */
    public static String delimiter = ";";
    
    public DatabaseItem()
    {
        
    }
    public DatabaseItem(String[] init, int id)
    {
        items = new ArrayList<String>();
        items.add(Integer.toString(id));
        items.addAll(Arrays.asList(init));        
    }
    /**
     * zmeni atributy polozky
     * @param field atribut ke zmene
     * @param new_item nova hodnota atributu field
     */
    public void edit_item(int field, String new_item) 
    {   
        if((field > 1)&&(field < items.size()))
            items.set(field, new_item);          
        else
           throw new IllegalArgumentException();
    }
    public String get(int index)
    {
        return items.get(index);
    }    
    @Override public String toString()
    {
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < items.size(); ++i)
        {
            if(i != 0)
                sb.append(delimiter);
            sb.append(items.get(i));
        }
        return sb.toString();
    }

}
